package ru.vsu.cs.pm.models;

import javax.persistence.*;
import java.io.Serializable;

/**
 * User: Oleg
 * Date: 23.12.2010
 * Time: 3:15:47
 */
@Entity
@Table(name = "account")
@NamedQueries({
        @NamedQuery(name = "account.get.by.user.id",
                query = "select a from Account a where a.user.id = :userId"),

        @NamedQuery(name = "account.get.count.by.user.id",
                query = "select count(a) from Account a where a.user.id = :userId"),

        @NamedQuery(name = "account.get.by.user.id.and.account.type",
                query = "select a from Account a left join fetch a.user " +
                        "where a.user.id = :userId and " +
                        "a.type in (:accountTypes) order by a.id"),

        @NamedQuery(name = "account.get.number.by.user.id.and.account.type",
                query = "select count(a) from Account a " +
                        "where a.user.id = :userId and " +
                        "a.type in (:accountTypes)")
})
public class Account implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    private User user;

    @Column(name = "title", nullable = false, length = 64)
    private String title;

    @Column(name = "description", nullable = true, length = 255)
    private String description;

    @Column(name = "money", nullable = false)
    private Long money;

    @Column(name = "account_type", nullable = false)
    private AccountType type;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getMoney() {
        return money;
    }

    public void setMoney(Long money) {
        this.money = money;
    }

    public AccountType getType() {
        return type;
    }

    public void setType(AccountType type) {
        this.type = type;
    }
}
